<?php
/* 	These code was generated using phpCIGen v 0.1.b (21/04/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	
	+ Module  		: t_payment Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_t_payment.php
 	+ creator 		: 
 	+ Created on 06/Mar/2012 12:35:49
	
*/

//class of t_payment
class C_t_payment extends CI_Controller {

	//constructor
	function C_t_payment(){
		parent::__construct();
		session_start();
		$this->load->model('m_t_payment', '', TRUE);
	}
	
	//set index
	function index(){
		$this->load->view('main/v_t_payment');
	}
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->t_payment_list();
				break;
			case "UPDATE":
				$this->t_payment_update();
				break;
			case "CREATE":
				$this->t_payment_create();
				break;
			case "DELETE":
				$this->t_payment_delete();
				break;
			case "SEARCH":
				$this->t_payment_search();
				break;
			case "PRINT":
				$this->t_payment_print();
				break;
			case "EXCEL":
				$this->t_payment_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function t_payment_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_t_payment->t_payment_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function t_payment_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$t_bill_id=@$_POST["t_bill_id"];
		$t_bill_id=is_numeric($t_bill_id)?$t_bill_id:0;
		$payment_date=trim(@$_POST["payment_date"]);
		$payment_type=trim(@$_POST["payment_type"]);
		$payment_type=htmlentities($payment_type,ENT_QUOTES);
		$payment_value=trim(@$_POST["payment_value"]);
		$payment_note=trim(@$_POST["payment_note"]);
		$payment_note=htmlentities($payment_note,ENT_QUOTES);
		$result=$this->m_t_payment->t_payment_create($t_bill_id ,$payment_date ,$payment_type ,$payment_value ,$payment_note );
		echo $result;
	}
	
	
	//function for update record
	function t_payment_update(){
		//POST variable here
		$payment_id=@$_POST["payment_id"];
		$payment_id=is_numeric($payment_id)?$payment_id:0;
		$t_bill_id=@$_POST["t_bill_id"];
		$t_bill_id=is_numeric($t_bill_id)?$t_bill_id:0;
		$payment_date=trim(@$_POST["payment_date"]);
		$payment_type=trim(@$_POST["payment_type"]);
		$payment_type=htmlentities($payment_type,ENT_QUOTES);
		$payment_value=trim(@$_POST["payment_value"]);
		$payment_note=trim(@$_POST["payment_note"]);
		$payment_note=htmlentities($payment_note,ENT_QUOTES);
		$result = $this->m_t_payment->t_payment_update($payment_id,$t_bill_id,$payment_date,$payment_type,$payment_value,$payment_note);
		echo $result;
	}
	
	//function for delete selected record
	function t_payment_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_t_payment->t_payment_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function t_payment_search(){
		//POST varibale here
		$payment_id=@$_POST["payment_id"];
		$payment_id=is_numeric($payment_id)?$payment_id:0;
		$t_bill_id=@$_POST["t_bill_id"];
		$t_bill_id=is_numeric($t_bill_id)?$t_bill_id:0;
		$payment_date=trim(@$_POST["payment_date"]);
		$payment_type=trim(@$_POST["payment_type"]);
		$payment_type=htmlentities($payment_type,ENT_QUOTES);
		$payment_value=trim(@$_POST["payment_value"]);
		$payment_note=trim(@$_POST["payment_note"]);
		$payment_note=htmlentities($payment_note,ENT_QUOTES);
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_t_payment->t_payment_search($payment_id ,$t_bill_id ,$payment_date ,$payment_type ,$payment_value ,$payment_note ,$start,$end);
		echo $result;
	}


	function t_payment_print(){
  		//POST varibale here
		$payment_id=@$_POST["payment_id"];
		$payment_id=is_numeric($payment_id)?$payment_id:0;
		$t_bill_id=@$_POST["t_bill_id"];
		$t_bill_id=is_numeric($t_bill_id)?$t_bill_id:0;
		$payment_date=trim(@$_POST["payment_date"]);
		$payment_type=trim(@$_POST["payment_type"]);
		$payment_type=htmlentities($payment_type,ENT_QUOTES);
		$payment_value=trim(@$_POST["payment_value"]);
		$payment_note=trim(@$_POST["payment_note"]);
		$payment_note=htmlentities($payment_note,ENT_QUOTES);
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_t_payment->t_payment_print($payment_id ,$t_bill_id ,$payment_date ,$payment_type ,$payment_value ,$payment_note ,$option,$filter);
		$print_view=$this->load->view("main/p_t_payment.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_payment_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function t_payment_export_excel(){
		//POST varibale here
		$payment_id=@$_POST["payment_id"];
		$payment_id=is_numeric($payment_id)?$payment_id:0;
		$t_bill_id=@$_POST["t_bill_id"];
		$t_bill_id=is_numeric($t_bill_id)?$t_bill_id:0;
		$payment_date=trim(@$_POST["payment_date"]);
		$payment_type=trim(@$_POST["payment_type"]);
		$payment_type=htmlentities($payment_type,ENT_QUOTES);
		$payment_value=trim(@$_POST["payment_value"]);
		$payment_note=trim(@$_POST["payment_note"]);
		$payment_note=htmlentities($payment_note,ENT_QUOTES);
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$query = $this->m_t_payment->t_payment_export_excel($payment_id ,$t_bill_id ,$payment_date ,$payment_type ,$payment_value ,$payment_note ,$option,$filter);
		
		to_excel($query,"t_payment"); 
		echo '1';
			
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
	
	
}
?>